﻿/*-------------------------------------------------------------------------
* 命名空间: SiliconSelect.Base/GlobalValues
* 类       名: GlobalValues
* 功      能:  TD
* 时      间:  2023/6/21 10:49:38
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using SiliconSelect.Common;
using SiliconSelect.DAL.DataEntity;
using SiliconSelect.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace SiliconSelect.Base
{
    public class GlobalValues
    {
        static GlobalValues()
        {
            SummaryTitle = SummaryTitle.Concat(CommanTitle).Concat(Title3D01).Concat(ResistivityTitle).Concat(SizeTitle).Concat(EdgeBreakFrontTitle).
                Concat(EdgeBreakBackTitle).Concat(EdgeBreakLeftTitle).Concat(EdgeBreakRightTitle).Concat(Title3D02).Concat(SumdgeUpTitle).
                Concat(SumdgeDownTitle).Concat(SubfissureTitle).ToList();
            LogHelper.WriteLog(LogType.Info, $"SummaryTitleLength = 96? {SummaryTitle.Count}");
        }
        public static UserEntity? UserInfo { get; set; } = new UserEntity()
        {
            Role = "操作员",
            Password = "",
            Username = "Guest",
            CreateBy = "System",
            CreateTime = DateTimeHelper.GetTimeNowForSql(),
            LastLoginTime = DateTimeHelper.GetTimeNowForSql()
        };


        /// <summary>
        /// 界面上显示的检测类型的名称,这些是固定要显示的,前面是等级,后面是要显示的类型.
        /// </summary>
        //public static string[] DetectedTypeNamesDefineSelf =
        //{
        //    "1. YJ1(0.2-0.4)","2. YJ2(0.4-1.1)","3. YJ3(1.1-1.5)","4. GEO(0.4-1.1)","5. GEO",
        //    "6. Stain","7. Chips","8. TTV","9. SM","10. Thin", "11. C-Pian","12. D-Pian",
        //    "13. TFC","14. Holes","15. Break","无等级","连片","反向","遮挡","卡片","缺数","汇总",
        //    "正常分选汇总"
        //};
        //  自定义的等级检测
        public static Dictionary<int, string> DetectedTypeNamesDefineSelf = new Dictionary<int, string>()
        {
            {30,"无等级直流" },
            {31,"缺数直流" },
            {32,"直流"},
            {33,"遮挡报警" },
            {34,"错位报警" },
            {35,"PLC通讯异常" },
            {36,"3D工位误触发"},
            {37,"3D数据错乱" },
            {38,"汇总" },
            {39,"正常分选汇总"}
        };

        // 视觉自定义异常,用来归类的时候往汇总表里面写入.
        public static Dictionary<string, string> VisionErrorWithWaferId = new Dictionary<string, string>();

        /// <summary>
        /// 总汇总数量,就是左侧界面.为了计算百分比所以写在这里比较好.
        /// </summary>
        public static int TotalWaferCount = 0;

        /// <summary>
        /// 所有的检测等级 键是等级,然后值是等级描述.
        /// </summary>
        public static Dictionary<int, string> DetectedTypeNamesTotal = new Dictionary<int, string>();

        // 客户一共开启了多少个正常检测等级,默认是15个. 程序里面是要可以计算的.
        public static int NormalDetectedTotalCounts = 15;

        /// <summary>
        /// 配方的默认文件夹,再和配方名称一起拼接成配方绝对路径
        /// </summary>
        public static string RecipeImportDir = @"D:\配方文件夹";
        public static string RecipeImportFile = "DefaultRecipe.xlsx";


        // 生产配方的目录和对应的文件名.
        public static string ProductionRecipeDir = @"C:\生产配方";
        public static string ProductionRecipeName = "DefaultRecipe.xlsx";
        /// <summary>
        /// 配方路径,目前默认的配方路径是这个
        /// </summary>
        public static string PordutionRecipePath = Path.Combine(ProductionRecipeDir, ProductionRecipeName);
        // 如果配方不存在,就按照项目的默认配方去加载一个
        public static string PordutionRecipePathDefault = Path.Combine(ProductionRecipeDir, @"DefaultRecipe.xlsx");
        //public static string PordutionRecipePathDefault = Path.Combine(RecipeDirDefault, @"Assets\Files\DefaultRecipe.csv");

        // 配方导入的路径,在WorkingInfo里面保存.

        /// <summary>
        /// 加载到的检测规则Rule.
        /// </summary>
        public static string DetectedRulePath = Path.Combine(ProductionRecipeDir, @"DetectedRuleUsed.txt");


        /// <summary>
        /// 当前作业的晶棒编号
        /// </summary>
        public static string? CrystalNumberCurrent { get; set; } = "Test001";

        /// <summary>
        /// 前一个晶棒编号
        /// </summary>
        public static string? LastCrystalNumber { get; set; }

        /// <summary>
        /// 预输入下一个编号的数据.
        /// </summary>
        public static string? CrystalNumberNext { get; set; }

        public static string? PostionNumberNext { get; set; }

        public static string? ProductionLotNext { get; set; }

        public static string? FlowerNumberNext { get; set; }

        public static int? TheoryNumberNext { get; set; }


        // 位置编号
        public static string? PositionNumber { get; set; }

        // 生产批次
        public static string? ProductionLot { get; set; }

        // 花篮号
        public static string? FlowerNumber { get; set; }

        // 切割编号
        public static string? CutNumber { get; set; }

        /// <summary>
        /// 所有的料盒编号
        /// </summary>
        public static List<string> BoxNames = new List<string>()
        {
            "料盒: 1","料盒: 2",  "料盒: 3","料盒: 4",  "料盒: 5","料盒: 6",
            "料盒: 7","料盒: 8",  "料盒: 9","料盒: 10",  "料盒: 11","料盒: 12",
            "料盒: 13","料盒: 14",  "料盒: 15","料盒: 16",  "料盒: 17","料盒: 18",
        };

        /// <summary>
        /// 检测等级和料盒对应关系.
        /// 一个检测等级可能对应多个料盒, 多个检测等级也可能是一个料盒.`    
        /// </summary>
        public static Dictionary<int, List<int>> LevelBoxMap = new Dictionary<int, List<int>>();

        /// <summary>
        /// 电阻率的流水号
        /// </summary>
        public static string WaferIdOfResistivity = "1000";

        /// <summary>
        /// 电阻率的检测结果.将检测结果放到这里来,至于最后是什么等级的,按理说后面跟的结果就是分类等级了.
        /// 分类的处理在消息处理那里已经处理好了.一个是流水号,一个是检测结果对应的等级.
        /// </summary>
        public static Dictionary<string, string> ResistivityDetectedMap = new Dictionary<string, string>();

        /// <summary>
        /// 电阻率数据获取方式,有三种
        /// </summary>
        public static int ResistivityDataGetMode = (int)GetDataMode.简易合并;

        /// <summary>
        ///  流水号绑定它对应的检测等级.里面的那个字典表示的是,检测项,检测等级. 这样后面也好排查.但是这里后面跟int不行了,这里要筛选出来公共等级的.
        /// </summary>
        public static Dictionary<string, Dictionary<string, List<int>>> WaferIdLevelDictionary = new Dictionary<string, Dictionary<string, List<int>>>();

        /// <summary>
        /// 流水号绑定的PC端的消息.用来判断在分选的时候,这些消息是否都已经收到,主要用来检测是否有消息缺失.
        /// </summary>
        public static Dictionary<string, List<string>> WaferIdFromPcDictionary = new Dictionary<string, List<string>>();

        ///// <summary>
        ///// 主要是来记录时间更新时间(用电阻率和隐裂工位作为标准) 然后如果超过了4秒,就去汇总. 如果汇总的时候数据有缺失,就报缺数直流.
        ///// </summary>
        public static Dictionary<string, DateTime> WaferIdDateSummary = new Dictionary<string, DateTime>();

        // 汇总目录
        public static string SummaryByDayDir = @"C:\结果汇总\KY02";
        public static string SummaryByCrystalNumberDir = @"C:\结果汇总\KY02";

        // 汇总文件路径带文件名的
        public static string SummaryByDayPath = "";
        public static string SummaryByCrystalNumberPath = "";

        // 汇总导出默认目录
        public static string SummaryExportDir = @"C:\结果汇总\导出汇总";
        public static string SummaryExportPath = "";

        // 国产电阻率目录
        public static string ResistivityDataDir = @"D:\国产电阻率";
        public static string ResistivityDataPath = "";

        // 用来保存流水号对应的数据,其实最后保存的时候,如果数据缺失就不保存就行了,保存为空. 
        public static Dictionary<string, string[]> WaferDataComman = new Dictionary<string, string[]>();

        // 用来保存3D工位数据第一部分
        public static Dictionary<string, string[]> WaferData3d01 = new Dictionary<string, string[]>();
        // 用来保存3D工位数据第二部分
        public static Dictionary<string, string[]> WaferData3D02 = new Dictionary<string, string[]>();

        // 用来保存电阻率工位数据
        public static Dictionary<string, string[]> WaferDataResistivity = new Dictionary<string, string[]>();

        // 用来保存尺寸工位数据
        public static Dictionary<string, string[]> WaferDataSize = new Dictionary<string, string[]>();

        // 用来保存崩边工位数据
        public static Dictionary<string, string[]> WaferDataEdgeBreak = new Dictionary<string, string[]>();

        // 用来保存脏污工位的数据
        public static Dictionary<string, string[]> WaferDataSumdge = new Dictionary<string, string[]>();

        // 用来保存隐裂工位的数据
        public static Dictionary<string, string[]> WaferDataSubfissure = new Dictionary<string, string[]>();

        // 汇总的时候数据的标题(公共标题,各个工位的标题加一起,防止后续改动的时候改动地方太大)
        // 公共标题
        public static string[] CommanTitle = { "操作时间", "生产班次日期", "产品流水号", "切割编号", "晶棒编号", "位置编号", "批次号", "花篮号", "配方名称", "汇总等级", "等级类型", "类型描述", "入选料盒" };
        // 3D工位标题
        public static string[] Title3D01 = { "平均厚度", "TTV", "线痕最大值", "翘曲" };
        // 电阻率
        public static string[] ResistivityTitle = { "电阻率值", "电阻率最大值", "电阻率最小值" }; // 17, 18,19
        // 尺寸工位标题
        public static string[] SizeTitle = {"X边长最大值","X边长最小值","Y边长最大值","Y边长最小值","边长最大值","边长最小值","X边长","Y边长","对角线左上右下","对角线左下右上",
            "倒角最大值","倒角最小值","上下平行度","左右平行度","直角边最大值","直角边最小值","垂直度最大值","垂直度最小值","左上倒角","右上倒角","左下倒角",
            "右下倒角","左上角度","右上角度","左下角度","右下角度"};  // 20,21,22,23,24,25,26,27,28,29,30,31., 45
        // 崩边工位标题
        public static string[] EdgeBreakFrontTitle = { "前崩边有无", "前崩边数量", "前崩边面积" }; // 46 47 48

        public static string[] EdgeBreakBackTitle = { "后崩边有无", "后崩边数量", "后崩边面积" }; // 49 50 51

        public static string[] EdgeBreakLeftTitle = { "左崩边有无", "左崩边数量", "左表崩有无", "左表崩数量" }; // 52 53 54 55

        public static string[] EdgeBreakRightTitle = { "右崩边有无", "右崩边数量", "右表崩有无", "右表崩数量" }; // 56,57,58,59

        public static string[] Title3D02 = { "最小厚度", "最大厚度", "是否密集线痕", "上线痕数量", "上线痕数量最大值", "下线痕数量", "下线痕数量最大值", "线痕数量" }; // 60,61,62,63,64,65,66,67
        // 脏污工位标题
        public static string[] SumdgeUpTitle = { "上脏污有无", "上脏污面积", "上脏污数量", "上脏污是否反向", "上脏污缺口有无", "上脏污穿孔有无" }; // 68,69,70,71,72,73

        public static string[] SumdgeDownTitle = { "下脏污有无", "下脏污面积", "下脏污数量", "下脏污是否反向", "下脏污缺口有无", "下脏污穿孔有无" }; // 74,75,76,77,78,79

        // 隐裂工位标题
        public static string[] SubfissureTitle = { "隐裂1隐裂有无", "隐裂1隐裂面积", "隐裂1隐裂数量", "隐裂1崩边有无", "隐裂1崩边面积", "隐裂1崩边数量", "隐裂1孔洞有无", "隐裂1孔洞数量",
            "隐裂2隐裂有无", "隐裂2隐裂面积", "隐裂2隐裂数量", "隐裂2崩边有无", "隐裂2崩边面积", "隐裂2崩边数量", "隐裂2孔洞有无", "隐裂2孔洞数量" };
        // 80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95.

        // 将所有的工位上的标题合并
        public static List<string> SummaryTitle = new List<string>();

        // 已经屏蔽的检测模块
        public static List<string> ModuleIsShield = new List<string>();

        // 最后一次统计的流水号的值,用来统计流水号是否有错位的情况.
        public static int LastWaferId = 0;

        // 直流的个数
        public static int DirectCount = 0;

        // 最后一次记录直流的时间
        public static DateTime LastDirectedTime = DateTime.Now;

        // 配方等级状态备份
        public static List<RecipeConfigModel> RecipeConfig = new List<RecipeConfigModel>();

        // 刷新数据进度条
        public static int DataInitProcess = 0;

        // 切换下一单进度条
        public static int SwitchInitProcess = 0;

        public static List<string> PcAddrList = new List<string>()
        {
            "192.168.1.20:50002",
            "192.168.1.20:50003","192.168.1.20:50013","192.168.1.20:50023","192.168.1.20:50033",
            "192.168.1.20:50004","192.168.1.20:50005","192.168.1.20:50015","192.168.1.20:50006",
        };

        // 电阻率的最后一个流水号,设备上电的时候赋值为0.
        public static int LastResistivityId = 0;

        // 电阻率流水号队列
        public static Queue<string> WaferIdQueue = new Queue<string>();

        // 电阻率流水号和对应的值绑定的队列
        public static Dictionary<string, Tuple<double, double, double, string>> ResistivityValMap = new Dictionary<string, Tuple<double, double, double, string>>();

        // 最后一块的厚度值
        public static double LastThickness = 150;

        // 补偿值列表所有工位的,用变量名对应的K和B的值
        public static Dictionary<string, double[]> VisionOffsetMap = new Dictionary<string, double[]>();

        // 是否接单状态
        public static bool CrystalFinishState = false;

        /// <summary>
        /// 是否显示界面上的弹窗
        /// </summary>
        public static bool DialogIsVisible = false;

        // 国产电阻率的K和B
        public static double ResistivityK = 1.0;
        public static double ResistivityB = 0.0;

        // 保存Napons电阻率的队列
        public static Queue<string[]> NaponsResistivityQueue = new Queue<string[]>();

        // 电阻率数据标题
        public static List<string> ResistivityDataTitle = new List<string>()
        {
            "流水号","厚度","Napons电阻率","最大值","最小值","PN","国产电阻率","最大值","最小值","PN"
        };


        // PCName 和 ClientName的映射
        public static Dictionary<string, string> PcClientMap = new Dictionary<string, string>()
        {
            { "Size","尺寸"},{ "LeftEdge","左崩"},{"RightEdge","右崩"},{ "FrontEdge","前崩"},
            { "BackEdge","后崩"},{ "ThreeD","3D"},{"SmuDown","下脏污" },{ "SmuUp","上脏污"},
            {"Subfi","隐裂" }
        };

    }
}
